#ifndef _RIGIDBODYCOMP_H_
#define _RIGIDBODYCOMP_H_

#include <SECore/Ecs/Component.h>
#include <SECore/Reflect.h>
#include <SEPhysics/Entity/RigidBodyPayload.h>

namespace SEngine
{
    struct RigidBodyComp : public Component<RigidBodyComp>, public RigidBodyPayload
    {
        ENABLE_SERIALIZE(Component<RigidBodyComp>)
        RigidBodyComp(Actor & actor);
        virtual ~RigidBodyComp();
        void BeforeUpdate() override;
        void Attach() override;
        void OnUpdate(int delta) override;
        void StartSimulation();
        void StopSimulation();
        virtual void OnUpdateTransform() override;

    
        glm::mat4 initialState;
        glm::mat4 lastState;

        /* Serialize */
        glm::vec3 linearVelocity{0.0f};
        glm::vec3 linearFactor{1.0f};
        glm::vec3 angularVelocity{0.0f};
        glm::vec3 angularFactor{1.0f};
        float friction{0.5f};
        float restitution{0.0f};
        float mass{1.0f};
        glm::vec3 offset{0.0f};
        int shapeType{0};
        bool isTrigger{false};
        /* For Box And Cylinder*/
        glm::vec3 size{0.5f};
        /* For Sphere And Capsule*/
        float radius{1.0f};
        /* For Capsule*/
        float height{1.0f};
    };   

    REF_REGISTER_CLASS(RigidBodyComp,
        REF_REGISTER_FIELD(RigidBodyComp, linearVelocity),
        REF_REGISTER_FIELD(RigidBodyComp, linearFactor),
        REF_REGISTER_FIELD(RigidBodyComp, angularVelocity),
        REF_REGISTER_FIELD(RigidBodyComp, angularFactor),
        REF_REGISTER_FIELD(RigidBodyComp, friction),
        REF_REGISTER_FIELD(RigidBodyComp, restitution),
        REF_REGISTER_FIELD(RigidBodyComp, mass),
        REF_REGISTER_FIELD(RigidBodyComp, offset),
        REF_REGISTER_FIELD(RigidBodyComp, shapeType),
        REF_REGISTER_FIELD(RigidBodyComp, isTrigger),
        REF_REGISTER_FIELD(RigidBodyComp, size),
        REF_REGISTER_FIELD(RigidBodyComp, radius),
        REF_REGISTER_FIELD(RigidBodyComp, height)
    )

} // namespace SEngine


#endif